package xyz.labmem.app.config

import com.alibaba.fastjson2.JSONObject
import javafx.scene.Cursor
import javafx.scene.image.Image
import javafx.scene.media.Media
import xyz.labmem.util.YamlUtil
import xyz.labmem.util.getResourceFile

object AppConfig {

    val ymlConfig: JSONObject = YamlUtil.getYaml()

    val appName = ymlConfig.getJSONObject("lipx").getString("name")

    val font = getResourceFile("font/AlimamaShuHeiTi-Bold.ttf").url.toExternalForm()

    val appIcon = ymlConfig.getJSONObject("lipx").getString("icon")

    val trayIcon = ymlConfig.getJSONObject("lipx").getString("tray-icon")

    val mouseImage = HashMap<String, Cursor>(
        mapOf(
            "m1" to Cursor.cursor(getResourceFile("image/ui/mouse/m1.gif").url.toExternalForm())
        )
    )

    val portraitsImage = HashMap<String, Image>()

    val messageImage = HashMap<String, Image>()

    val uiImage = HashMap<String, Image>()

    val musicMedia = Media(getResourceFile("sound/Lyn-Life-Will-Change.mp3").url.toExternalForm())

    val loadingImage = HashMap<Any, Image>(
        mapOf(
            0 to Image(getResourceFile("image/ui/crowd/crowd0.png").url.toExternalForm(), true),
            1 to Image(getResourceFile("image/ui/crowd/crowd1.png").url.toExternalForm(), true),
            2 to Image(getResourceFile("image/ui/crowd/crowd2.png").url.toExternalForm(), true),
            3 to Image(getResourceFile("image/ui/crowd/crowd3.png").url.toExternalForm(), true),
            4 to Image(getResourceFile("image/ui/crowd/crowd4.png").url.toExternalForm(), true),
            5 to Image(getResourceFile("image/ui/crowd/crowd5.png").url.toExternalForm(), true),
            6 to Image(getResourceFile("image/ui/crowd/crowd6.png").url.toExternalForm(), true),
            7 to Image(getResourceFile("image/ui/crowd/crowd7.png").url.toExternalForm(), true),
            8 to Image(getResourceFile("image/ui/crowd/crowd8.png").url.toExternalForm(), true),
            9 to Image(getResourceFile("image/ui/crowd/crowd9.png").url.toExternalForm(), true),
            10 to Image(getResourceFile("image/ui/crowd/crowd10.png").url.toExternalForm(), true),
            11 to Image(getResourceFile("image/ui/crowd/crowd11.png").url.toExternalForm(), true),
            "loading" to Image(getResourceFile("image/ui/loading.gif").url.toExternalForm(), true),
        )
    )

    fun initConfig() {
        portraitsImage.putAll(
            mapOf(
                "akechi" to Image(getResourceFile("image/ui/portraits/akechi.png").url.toExternalForm(), true),
                "ann" to Image(getResourceFile("image/ui/portraits/ann.png").url.toExternalForm(), true),
                "futaba" to Image(getResourceFile("image/ui/portraits/futaba.png").url.toExternalForm(), true),
                "haru" to Image(getResourceFile("image/ui/portraits/haru.png").url.toExternalForm(), true),
                "kasumi" to Image(getResourceFile("image/ui/portraits/kasumi.png").url.toExternalForm(), true),
                "lavenza" to Image(getResourceFile("image/ui/portraits/lavenza.png").url.toExternalForm(), true),
                "makoto" to Image(getResourceFile("image/ui/portraits/makoto.png").url.toExternalForm(), true),
                "mona" to Image(getResourceFile("image/ui/portraits/mona.png").url.toExternalForm(), true),
                "ryuji" to Image(getResourceFile("image/ui/portraits/ryuji.png").url.toExternalForm(), true),
                "sumire" to Image(getResourceFile("image/ui/portraits/sumire.png").url.toExternalForm(), true),
                "yusuke" to Image(getResourceFile("image/ui/portraits/yusuke.png").url.toExternalForm(), true),
            )
        )
        messageImage.putAll(
            mapOf(
                "clear" to Image(getResourceFile("image/ui/msg/clear.png").url.toExternalForm(), true),
                "default" to Image(getResourceFile("image/ui/msg/default.png").url.toExternalForm(), true),
                "fail" to Image(getResourceFile("image/ui/msg/fail.png").url.toExternalForm(), true),
                "notification" to Image(getResourceFile("image/ui/msg/notification.png").url.toExternalForm(), true),
            )
        )
        uiImage.putAll(
            mapOf(
                "close" to Image(getResourceFile("image/ui/close.png").url.toExternalForm(), true),
                "default" to Image(getResourceFile("image/ui/default.png").url.toExternalForm(), true),
                "star" to Image(getResourceFile("image/ui/star.png").url.toExternalForm(), true),
                "star1" to Image(getResourceFile("image/ui/star1.png").url.toExternalForm(), true),
                "star2" to Image(getResourceFile("image/ui/star2.png").url.toExternalForm(), true),
                "upload" to Image(getResourceFile("image/ui/upload.png").url.toExternalForm(), true),
                "zoom" to Image(getResourceFile("image/ui/zoom.png").url.toExternalForm(), true),
                "bg" to Image(getResourceFile("image/ui/bg.png").url.toExternalForm(), true),
                "t_bg" to Image(getResourceFile("image/ui/t_bg.png").url.toExternalForm(), true),
                "sword" to Image(getResourceFile("image/ui/sword.png").url.toExternalForm(), true),
                "m4" to Image(getResourceFile("image/ui/mouse/m4.gif").url.toExternalForm(), true),
                "exit" to Image(getResourceFile("image/ui/exit.png").url.toExternalForm(), true),
                "bg1" to Image(getResourceFile("image/ui/bg1.png").url.toExternalForm(), true),
            )
        )
        mouseImage.putAll(
            mapOf(
                "m2" to Cursor.cursor(getResourceFile("image/ui/mouse/m2.gif").url.toExternalForm()),
                "m3" to Cursor.cursor(getResourceFile("image/ui/mouse/m3.gif").url.toExternalForm()),
                "m5" to Cursor.cursor(getResourceFile("image/ui/mouse/m5.gif").url.toExternalForm()),
                "m6" to Cursor.cursor(getResourceFile("image/ui/mouse/m6.gif").url.toExternalForm()),
            )
        )
        loadingImage.putAll(
            mapOf(
                "load-bg1" to Image(getResourceFile("image/ui/loading/bg1.png").url.toExternalForm(), true),
                "load-bg2" to Image(getResourceFile("image/ui/loading/bg2.png").url.toExternalForm(), true),
                "load-bg3" to Image(getResourceFile("image/ui/loading/bg3.png").url.toExternalForm(), true),
                "load-cloud1" to Image(getResourceFile("image/ui/loading/cloud1.png").url.toExternalForm(), true),
                "load-cloud2" to Image(getResourceFile("image/ui/loading/cloud2.png").url.toExternalForm(), true),
            )
        )
    }

}